package avicit.bdp.dcs.desensitization.rest;

import avicit.bdp.dcs.desensitization.dto.DcsDesensitizationPolicyDTO;
import avicit.bdp.dcs.desensitization.service.DesensitizationPolicyService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-08-03 09:12
 * @类说明：脱敏策略接口
 * @修改记录：
 */
@RestController
@RequestMapping("/api/bdp/dcs/desensitization/DesensitizationPolicyRest")
@Api(tags = "脱敏策略接口")
public class DesensitizationPolicyRest {

    private static final Logger logger = LoggerFactory.getLogger(DesensitizationPolicyRest.class);

    @Autowired
    private DesensitizationPolicyService desensitizationPolicyService;

    @GetMapping("/getPolicyListByRuleId")
    @ApiOperation(value = "根据规则id查询脱敏策略")
    public ResponseMsg<List<DcsDesensitizationPolicyDTO>> getPolicyListByRuleId(@ApiParam(value = "脱敏规则ID", name = "ruleId", required = true)  @RequestParam String ruleId){
        ResponseMsg<List<DcsDesensitizationPolicyDTO>> responseMsg = new ResponseMsg<>();
        try {
            responseMsg.setResponseBody(desensitizationPolicyService.getPolicyListByRuleId(ruleId));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            responseMsg.setRetCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
            responseMsg.setErrorDesc(e.getMessage());
        }
        return responseMsg;
    }

}
